export default {
  bind(el, { value, arg }) {
    let timer = null;
    let delay = arg || 800; // 默认800
    el.$handle = () => {
      clearTimeout(timer);
      timer = setTimeout(() => {
        value();
      }, delay);
    };
    el.$cancel = () => {
      clearTimeout(timer);
    };
    // pc 端
    el.addEventListener('mousedown', el.$handle);
    el.addEventListener('mouseup', el.$cancel);
    // 移动端
    el.addEventListener('touchstart', el.$handle);
    el.addEventListener('touchsend', el.$cancel);
  },
  unbind(el) {
    el.removeEventListener('mousedown', el.$handle);
    el.addEventListener('mouseup', el.$cancel);
    el.addEventListener('touchstart', el.$handle);
    el.addEventListener('touchsend', el.$cancel);
  }
};
